<?php
session_start();
require 'connect.php';
$strSQL = "SELECT * FROM officer WHERE OfficerID = '".$_SESSION['OfficerID']."' ";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);

$meSql = "SELECT * , a.book_code as aa FROM books a 
            LEFT JOIN rental_details b ON a.id = b.book_id
            where b.book_id IS NULL
";
$meQuery = mysql_query($meSql);

$action = isset($_GET['a']) ? $_GET['a'] : "";
$itemCount = isset($_SESSION['cart']) ? count($_SESSION['cart']) : 0;
if(isset($_SESSION['qty'])){
    $meQty = 0;
    foreach($_SESSION['qty'] as $meItem){
        $meQty = $meQty + $meItem;
    }
}else{
    $meQty=0;
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>เช่าหนังสือ</title>

        <!-- Bootstrap -->
        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <link href="bootstrap/css/nava.css" rel="stylesheet">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

    <style type="text/css">
    body {
	background-color: #FFEAFF;
}
    body,td,th {
	color: #000;
}
    </style>
    </head>
    <body>
        <div class="container">

            <!-- Static navbar -->
            <div class="navbar navbar-default" role="navigation">
              <div class="container-fluid">
                  <div class="navbar-header">
                    <p><img src="images/mix.jpg" width="876" height="186"></p>
                    <table width="876" height="31" border="1">
                      <tr align="center">
                        <td width="114" bgcolor="#FFCCCC"><a href="../back/list_officer.php">ข้อมูลพนักงาน</a></td>
                        <td width="104" bgcolor="#FFCCCC">ข้อมูลลูกค้า</td>
                        <td width="120" bgcolor="#FFCCCC">ข้อมูลหนังสือ</td>
                        <td width="149" bgcolor="#FFCCCC"><a href="../back/list_pub.php">ข้อมูลสำนักพิมพ์</a></td>
                        <td width="113" bgcolor="#FFCCCC"><a href="index.php">เช่าคืน</a></td>
                        <td width="97" bgcolor="#FFCCCC"><a href="../rent/index.php">จอง</a></td>
                        <td width="133" bgcolor="#FFCCCC">รายงาน</td>
                      </tr>
                    </table>
                  </div>
              <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a href="cart.php">หนังสือที่เช่า <span class="badge"><?php echo $meQty; ?></span></a></li>
                </ul>
              </div><!--/.nav-collapse -->
                </div><!--/.container-fluid -->
            </div>

            <!-- Main component for a primary marketing message or call to action -->

            <h3>หน้าแรกของสินค้า</h3>
            <p><a href="return.php">คืนหนังสือ</a></p>
<?php
if($action == 'exists'){
    echo "<div class=\"alert alert-warning\">เพิ่มจำนวนหนังสือแล้ว</div>";
}
if($action == 'add'){
    echo "<div class=\"alert alert-success\">เพิ่มหนังสือลงในตะกร้าเรียบร้อยแล้ว</div>";
}
if($action == 'order'){
	echo "<div class=\"alert alert-success\">เช่าหนังสือเรียบร้อยแล้ว</div>";
}
if($action == 'orderfail'){
	echo "<div class=\"alert alert-warning\">เช่าหนังสือไม่สำเร็จ มีข้อผิดพลาดเกิดขึ้นกรุณาลองใหม่อีกครั้ง</div>";
}
?>
            <table width="880" border="1" class="table table-striped">
                <thead>
                    <tr>
                        <th width="117" bgcolor="#FF9999">รูปภาพ</th>
                        <th width="166" bgcolor="#FF9999">รหัสหนังสือ</th>
                        <th width="215" bgcolor="#FF9999">ชื่อหนังสือ</th>
                        <th width="174" bgcolor="#FF9999">รายละเอียด</th>
                        <th width="102" bgcolor="#FF9999">ค่าเช่า</th>
                        <th width="66" bgcolor="#FF9999">&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    while ($meResult = mysql_fetch_assoc($meQuery))
                    {
                        ?>
                        <tr>
                            <td align="center"><img src="images/<?php echo $meResult['picture']; ?>" width="80" height="112" border="0"></td>
                            <td align="center"><?php echo $meResult['aa']; ?></td>
                            <td align="center"><?php echo $meResult['book_name']; ?></td>
                            <td align="center"><?php echo $meResult['book_desc']; ?></td>
                            <td align="center"><?php echo number_format($meResult['book_price'],2); ?> / วัน</td>
                            <td align="center">
                                <a class="btn btn-primary btn-lg" href="updatecart.php?itemId=<?php echo $meResult['id']; ?>" role="button">
                                    <span class="glyphicon glyphicon-shopping-cart"></span><img src="images/z8.jpg" width="161" height="69"></a>
                            </td>
                        </tr>
                        <?php
                    }
                    ?>
                </tbody>
            </table>

        </div> <!-- /container -->

        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="bootstrap/js/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="bootstrap/js/bootstrap.min.js"></script>
    </body>
</html>
<?php
mysql_close();
?>